package com.saint.farmshop.Controller;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.saint.farmshop.Entity.Production;
import com.saint.farmshop.Entity.ProductionDetail;
import com.saint.farmshop.Entity.ProductionSecondType;
import com.saint.farmshop.Service.ServiceImpl.ProductionServiceImpl;
import com.saint.farmshop.Utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * 产品控制器
 *
 * @author Saint
 * @date 2022/05/22
 */
@Slf4j
@RestController
@RequestMapping("/production")
public class ProductionController {

    @Resource
    ProductionServiceImpl productionService;

    @RequestMapping("/addProduction")
    public Result addProduction(@RequestBody ProductionDetail productionDetail){
        return productionService.releaseProduction(productionDetail);
    }

    @RequestMapping("/myProduction/{pageIndex}")
    public List<Production> getMyProduction(@PathVariable("pageIndex") Integer pageIndex, @RequestParam String openId,@RequestParam Integer pageSize){
        return productionService.getProductionByOpenId(openId,pageIndex,pageSize);
    }

    @RequestMapping("/typeProduction/{pageIndex}")
    public List<Production> getTypeProduction(@PathVariable("pageIndex") Integer pageIndex, @RequestBody ProductionSecondType productionSecondType, @RequestParam Integer pageSize){
        return productionService.getProductionByType(productionSecondType,pageIndex,pageSize);
    }

    @RequestMapping("/deleteProduction")
    public Result deleteProduction(@RequestBody ProductionDetail productionDetail){
        return productionService.deleteProduction(productionDetail);
    }

    @RequestMapping("/getProductionList/{pageIndex}")
    public List<Production> getProductionList(@PathVariable("pageIndex") Integer pageIndex,@RequestParam Integer pageSize){
        return productionService.getProductionList(pageIndex,pageSize);
    }

}
